package com.ctg.itrdc.sysmgr.portal.control;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ctg.itrdc.pasp.core.PageInfo;
import com.ctg.itrdc.sysmgr.portal.api.dto.SystemRolesDTO;
import com.ctg.itrdc.sysmgr.portal.api.service.ISystemRolesService;
import com.ctg.itrdc.sysmgr.portal.common.entity.CommonResult;
import com.ctg.itrdc.sysmgr.portal.data.entity.SystemRoles;
import com.ctg.itrdc.sysmgr.portal.utils.DTOHelper;

@Controller
@RequestMapping("/system_roles")
public class SystemRolesController extends SysmgrCURDController<Long, SystemRolesDTO> {

	@Resource
	private ISystemRolesService systemRolesService;
	
	@RequestMapping("/insert")
	@ResponseBody
	public CommonResult insert(@Valid SystemRolesDTO dto ,BindingResult result) throws Exception {
		DTOHelper.valid(result);
		DTOHelper.updateDTO(dto);
		long id = systemRolesService.insert(dto);
		return new CommonResult(HttpStatus.OK.toString(), "新增数据成功",id);
	}
	
	@RequestMapping("/update")
	@ResponseBody
	@Override
	public CommonResult updateByPrimaryKey(SystemRolesDTO dto, BindingResult result) throws Exception {
		DTOHelper.valid(result);
		DTOHelper.updateDTO(dto);
		int i = systemRolesService.updateByPrimaryKey(dto);
		return new CommonResult(HttpStatus.OK.toString(), "更新数据成功",i);
	}

	/** 
	* @api {post} /system_roles/page/post2Roles 分页列表,返回包含sysPostRoleId
	* @apiGroup system_roles
	* @apiName page4Post
	* @apiParam {Long} sysPostId 岗位标识 为该岗位指定角色
	* @apiParam {Long} sysRoleId 角色标识 不可为空 
	* @apiParam {String} sysRoleName 角色名称 可为空 
	* @apiParam {String} sysRoleCode 角色编码 可为空 
	* @apiParam {String} sysRoleDesc 角色描述 可为空 
	* @apiParam {Long} commonRegionId 公用管理区域标识,记录区域唯一标识 可为空 
	* @apiParam {String} sysCode 系统用户的归属系统 可为空 
	* @apiParam {String} statusCd 状态 可为空 
	* @apiParam {Integer} currentPage 当前页数 从0开始
	* @apiParam {Integer} perPageNum  每页记录数
	* @apiVersion 0.0.1
	*/
	@RequestMapping("/page/post2Roles")
	@ResponseBody
	public CommonResult page4Post(
			SystemRolesDTO dto,
			@RequestParam Long sysPostId,
			@RequestParam(defaultValue = "0") Integer currentPage,
			@RequestParam(defaultValue = "100") Integer perPage
			){
		PageInfo<SystemRolesDTO> page = systemRolesService.queryPage4Post(dto,sysPostId, currentPage, perPage);
		return new CommonResult(HttpStatus.OK.toString(),"查询成功",page); 
	}
	
	/** 
	* @api {post} /system_roles/page/user2Roles 分页列表,返回包含sysUserRoleId
	* @apiGroup system_roles
	* @apiName page4User
	* @apiParam {Long} sysRoleId 角色标识 不可为空 
	* @apiParam {String} sysRoleName 角色名称 可为空 
	* @apiParam {String} sysRoleCode 角色编码 可为空 
	* @apiParam {String} sysRoleDesc 角色描述 可为空 
	* @apiParam {Long} commonRegionId 公用管理区域标识,记录区域唯一标识 可为空 
	* @apiParam {String} sysCode 系统用户的归属系统 可为空 
	* @apiParam {String} statusCd 状态 可为空 
	* @apiParam {Integer} currentPage 当前页数 从0开始
	* @apiParam {Integer} perPageNum  每页记录数
	* @apiVersion 0.0.1
	*/
	@RequestMapping("/page/user2Roles")
	@ResponseBody
	public CommonResult page4User(
			SystemRolesDTO dto,
			@RequestParam Long sysUserId,
			@RequestParam(defaultValue = "0") Integer currentPage,
			@RequestParam(defaultValue = "100") Integer perPage
			){
		PageInfo<SystemRolesDTO> page = systemRolesService.queryPage4User(dto, sysUserId,currentPage, perPage);
		return new CommonResult(HttpStatus.OK.toString(),"查询成功",page); 
	}
}
